#descriptive analysis
describe(wv6$V105)
summaryBy(happy~country, data=wv6, FUN=c(mean,sd), na.rm=T)
summaryBy(satlife~country, data=wv6, FUN=c(mean,sd), na.rm=T)
summaryBy(fam_trust~country, data=wv6, FUN=c(mean,sd), na.rm=T)
summaryBy(par_trust~country, data=wv6, FUN=c(mean,sd), na.rm=T)
summaryBy(gen_trust~country, data=wv6, FUN=c(mean,sd), na.rm=T)
summaryBy(sum_trust~country, data=wv6, FUN=c(mean,sd), na.rm=T)
summaryBy(health~country, data=wv6, FUN=c(mean,sd), na.rm=T)
##correlation of trust
cor.vars <- c("V102","V103","V104","V105")
cor.vars <- c("V102","V103","V104","V105")
cor.dat<-by.year.ts(,corvars)
data<- data.matrix(cor.vars,cor.vars)
cor(data)
?table
ctab <- table(wv6$V102,wv6$V103)
ctab <- table(wv6$V102,wv6$V102)
chisq.test(ctab)
addmargins(ctab)
ctab2 <- table(wv6$V102,wv6$V104)
chisq.test(ctab2)
ctab3 <- table(wv6$V102,wv6$V105)
chisq.test(ctab3)
ctab4 <- table(wv6$V103,wv6$V104)
chisq.test(ctab4)
(ct <- corresp(~ V102 + V104, data = wv6))
(ct <- corresp(~ V104 + V105, data = wv6))
(ct <- corresp(~ V102 + V105, data = wv6))
(ct <- corresp(~ V105 + V104, data = wv6))
chi2 = chisq.test(ctab2, correct=F)
chi2 = chisq.test(ctab3, correct=F)
chi2 = chisq.test(ctab4, correct=F)
chi2 = chisq.test(ctab, correct=F)
c(chi2$statistic, chi2$p.value)
sqrt(chi2$statistic / sum(ctab2))
sqrt(chi2$statistic / sum(ctab3))

#simple OLS
lm1 <- lm(satlife ~ fam_trust+par_trust+gen_trust+married+male+education+income+health+as.factor(religious)+as.factor(employment)+ln.GDP+Gini,data=wv6)
summary(lm1)
lm2 <- lm(happy ~ fam_trust+par_trust+gen_trust+married+male+education+income+health+as.factor(religious)+as.factor(employment)+ln.GDP+Gini,data=wv6)
summary(lm2)

#ordinal logistic regression of 57 countries
vglm1 <- vglm(as.numeric(happy) ~ fam_trust+par_trust+gen_trust+married+male+education+income+health+as.factor(religious)+as.factor(employment),subset=country=="Trinidad and Tobago",data=wv6,family = propodds)
summary(vglm1)
vglm2 <- vglm(as.numeric(satlife) ~ fam_trust+par_trust+gen_trust+married+male+education+income+health+as.factor(religious)+as.factor(employment),data=wv6,family = propodds)
summary(vglm2)